<template>
	<view>
		<!-- 标题栏 -->
		<view class="top-box tn-cool-bg-color-15--reverse" style="padding: 0 20rpx;">
			<view class="text-lg text-white text-bold margin-left-xs">我的提交申请</view>
			<view class="text-lg text-bold">{{ todayTime }}</view>
		</view>

		<!-- //申请审核楼栋长薪资 -->
		<view class="sort-content margin-top-xs">
			<view class="main-check margin-bottom-sm" v-for="(item, index) in authenticationList" :key="index">
				<view class="main-check-image" style="display: flex; width: 100%; height: auto;flex-direction: column;">
					<view class="" style="display: flex; width: 100%;flex-direction: column; padding: 10rpx 20rpx;">
						<view class="text-lg text-black margin-bottom-xs" style="display: flex;justify-content:space-between; align-items: center;">
							<text class="text-xxl text-black text-bold">{{item.data.type}}</text>
							<text v-if="item.data.status == 1" class="text-xxl text-black text-bold margin-left-lg bg-gradual-tougao">正在申请中</text>
							<text v-if="item.data.status == 2" class="text-xxl text-blue text-bold margin-left-lg bg-gradual-index">财务审核通过</text>
							<text v-if="item.data.status == 3" class="text-xxl text-gray text-bold margin-left-lg">已结算</text>
							<text v-if="item.data.status == 4" class="text-xxl text-red text-bold margin-left-lg bg-black">已驳回</text>
						</view>
						<view class="text-lg text-black" style="display: flex;justify-content: space-between; align-items: center;">
							薪资放发对象({{ item.data.louNum }}):
							<text class="text-red margin-left-xs text-bold">{{ item.data.nameUser }}</text>
							<text class="text-xs text-bold margin-left-lg">计算者:{{item.data.nameCharge}}</text>
						</view>
						<view class="margin-top-xs" style="display: flex;flex-direction: column;width: 100%;">
							<view style="width: 100%; box-shadow: 0rpx 3rpx rgba(0, 0, 0, 0.1);padding-bottom: 1rpx;" v-for="(itemOrder, indexOrder) in item.data.numOrder" :key="indexOrder">
								<view class="text-bold" style="display: flex;justify-content: space-between;align-items: center;" v-if="itemOrder.num && indexOrder != 8">
									<text>{{ itemOrder.name }}</text>
									<text class="margin-left-lg text-bold text-lg text-red;">{{ itemOrder.num }}单</text>
								</view>
								<view class="text-bold" style="display: flex;justify-content: space-between;align-items: center;"  v-if="itemOrder.num && indexOrder == 8">
									<text>{{ itemOrder.name }}</text>
									<text class="margin-left-lg text-bold text-xxl text-red">{{ itemOrder.num }}元</text>
								</view>
							</view>
						</view>
					</view>
					<view class="" style="display: flex; width: 100%;padding: 0 20rpx;" v-if="item.data.remark">
						<view class="" style="display: flex; width: 100%; align-items: center;justify-content: space-between;">
							<view class="text-bold">附加奖励：{{item.data.addMoney}}元</view>
							<view class="margin-left-lg">备注：{{item.data.remark}}</view>
						</view>
					</view>
					<view class="" style="display: flex; width: 100%;padding: 0 20rpx;align-items: center;">申请时间：<uni-dateformat :threshold="[60000, 60480000]" class="content-text-ps text-gray" :date="item.data.time"></uni-dateformat></view>
					<view class="bottom-button margin-top-xs">
						<button v-if="item.data.status == 4" class="cu-btn bg-orange round shadow-blur" @click="toLoudong(item._id)">重新修改提交</button>
		                <!-- <button class="cu-btn bg-red round shadow-blur margin-left-lg" @click="setBack(index)">驳回</button> -->
						<!-- <button class="cu-btn bg-red round shadow-blur margin-left-lg" @click="passCheck(index)">通过审核</button> -->
					</view>
				</view>
			</view>
		</view>
		<!--无内容显示-->
		<u-empty v-if="authenticationList.length < 1" margin-top="400" text="暂无通过列表" mode="data" icon-size="150"></u-empty>
		<!-- 息通知 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
const db = uniCloud.database();
export default {
	data() {
		return {
			authenticationList: [],
			list: [],
			page: 1,
			openid: '',
			todayTime: '', //当天时间
			scrollTop: 0,
			nomore: false,
			articleList: []
		};
	},
	onLoad() {
		let that = this;
		this.todayTime = new Date().toLocaleDateString();
	},
	onShow() {
		let that = this;
		//登陆验证
		that.chechLogin();
		// that.getComfirmList();
	},
	methods: {
		//驳回
		toLoudong(id){
			uni.showModal({
				title: '驳回单目前要重新提交一次审核，该记录保留',
				success(res) {
					return;
				}
			});
		},
		//判断登陆
		chechLogin() {
			let that = this;
			uni.getStorage({
				key: 'user_sxz',
				success(res) {
					//判断是否登陆
					if (res.data.openid == '' || res.data.openid == undefined) {
						uni.showModal({
							title: '您还没有绑定微信登陆，是否要现在进行绑定？',
							success(res) {
								uni.switchTab({
									url: '../../../me/me'
								});
								return;
							}
						});
					} else {
						console.log('获取到store本地数据', res);
						//1、赋值OPENID
						that.openid = res.data.openid;
						//2、请求数据
						that.getComfirmList();
					}
				},
				fail(res) {
					console.log('获取失败', res);
					uni.showModal({
						title: '您还没有绑定微信登陆，是否要现在进行绑定？',
						success(res) {
							uni.switchTab({
								url: '../../../me/me'
							});
							return;
						}
					});
				}
			});
		},
		//请求数据
		getComfirmList() {
			let that = this;
			db.collection('moneyCheck')
				.where({
					'data.openidCharge': that.openid
				})
				.orderBy('data.time', 'desc')
				.get({})
				.then(res => {
					that.authenticationList = res.result.data;
				})
				.catch(error => {
					console.log('获取认证数据库失败');
				});
		},

		//删除认证
		noPass(index) {
			let that = this;
			let authentid = that.authenticationList[index]._id;
			let openid = that.authenticationList[index].data.openid;
			uni.showModal({
				title: '是否删除该审核信息？',
				success(res) {
					if(res.confirm){
						uni.showLoading({
							title: '正在处理中...'
						});
						db.collection('moneyCheck')
							.doc(authentid)
							.remove()
							.then(res => {
								//本地操作删除
								uni.hideLoading();
								that.authenticationList.splice(index, 1);
								that.$refs.uToast.show({
									title: '成功删除！',
									type: 'success'
								});
							})
							.catch(res => {
								uni.hideLoading();
								that.$refs.uToast.show({
									title: '操作失败！',
									type: 'error'
								});
								console.log('数据库更新失败');
							});
					}
				}
			});
		},
		//驳回
		setBack(index){
			let that = this;
			let authentid = that.authenticationList[index]._id;
			let openid = that.authenticationList[index].data.openid;
			uni.showModal({
				title: '是否驳回该审核信息？',
				success(res) {
					if(res.confirm){
						uni.showLoading({
							title: '正在处理中...'
						});
						//数据库操作
						db.collection('moneyCheck')
							.doc(authentid)
							.update({
								data: {
									status: 4
								}
							})
							.then(res => {
								uni.hideLoading();
								that.authenticationList.splice(index, 1);
								that.$refs.uToast.show({
									title: '修改成功',
									type: 'success'
								});
							})
							.catch(res => {
								uni.hideLoading();
								console.log('数据库更新失败');
								that.$refs.uToast.show({
									title: '网络错误，请重试',
									type: 'error'
								});
							});
					}
				}
			});
		},
		//通过审核
		passCheck(index) {
			let that = this;
			let authentid = that.authenticationList[index]._id;
			let openid = that.authenticationList[index].data.openid;
			uni.showModal({
				title: '是否通过该审核信息？',
				success(res) {
					if(res.confirm){
						uni.showLoading({
							title: '正在处理中...'
						});
						//数据库操作
						db.collection('moneyCheck')
							.doc(authentid)
							.update({
								data: {
									status: 2
								}
							})
							.then(res => {
								uni.hideLoading();
								that.authenticationList.splice(index, 1);
								that.$refs.uToast.show({
									title: '修改成功',
									type: 'success'
								});
							})
							.catch(res => {
								uni.hideLoading();
								console.log('数据库更新失败');
								that.$refs.uToast.show({
									title: '网络错误，请重试',
									type: 'error'
								});
							});
					}
				}
			});
		}
	}
};
</script>

<style>
page {
	background-color: #f4faff;
}
.top-box {
	width: 100%;
	height: 100rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}
.ps {
	width: 100%;
	height: 30rpx;
	background-color: #f4faff;
}
.main-check {
	width: 100%;
	padding: 10rpx 0;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	border-radius: 20rpx;
	background: #fff;
}
.bottom-button {
	width: 100%;
	height: 100%;
	padding: 10rpx 20rpx;
	display: flex;
    align-items: center;
	/* justify-content: space-around; */
}
.main-check-image {
	align-items: center;
}
.header-punchCard {
	width: 100rpx;
	height: 50rpx;
	display: flex;
	align-items: center;
}
/* 留言和分类 */
.mess_sort {
	margin-top: 120rpx;
	width: 100%;
	/* background-color: blueviolet; */
}
/* 分类标签 */
.sort-nav {
	width: 100%;
	height: 180rpx;
	padding: 0 20rpx;
	display: flex;
	align-items: center;
	align-content: center;
}
::-webkit-scrollbar {
	width: 0;
	height: 0;
	color: transparent;
	display: none;
}
.sort-nav-item {
	display: inline-block;
	width: 94rpx;
	font-size: 20rpx;
	text-align: center;
	/* line-height: 4rpx; */
	color: #aaa;
	margin: 40rpx 34rpx 0rpx 20rpx;
}
.sort-nav-icon {
	width: 84rpx;
	height: 84rpx;
}
.sort-nav-text {
	display: block;
}
/* 实时留言 */
.message-image {
	width: 130rpx;
	height: 100%;
}
.swiper_message {
	float: right;
	display: inline-flex;
	height: 100%;
	width: 90%;
	/* background-color: brown; */
}
.swiper-item-message {
	padding: 0;
	display: flex;
	flex-direction: column;
}
.message {
	width: 100%;
	height: 75%;
	display: flex;
	justify-content: flex-start;
	text-overflow: ellipsis;
}
.message-ps {
	width: 95%;
	height: 25%;
	/* background-color: coral; */
	font-size: 20rpx;
	text-align: end;
}
.leave-message {
	width: 100%;
	height: 120rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
}
.message-content {
	height: 70%;
	width: 100%;
	padding: 10rpx 20rpx;
	font-size: 26rpx;
	line-height: 140%;
	overflow: hidden;
	letter-spacing: 2rpx;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	/* background-color: chocolate; */
}
.message-name {
	width: 20rpx;
	height: 20rpx;
	padding: 5rpx 4px;
	color: rgb(34, 173, 207);
	font-weight: 400;
	font-size: 27rpx;
	/* background-color: burlywood; */
}
/* 分类具体内容 */
.sort-content {
	justify-content: center;
	margin: auto;
	margin-left: 20rpx;
	margin-right: 20rpx;
	margin-top: 10rpx;
	/* background-color: aqua; */
}
.sort-content-item {
	padding-bottom: 20rpx;
	border-bottom: 3rpx rgb(240, 242, 243) solid;
}
.user-info {
	width: 100%;
	padding: 0 30rpx 0 10rpx;
	margin-top: 5rpx;
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	/* background-color: blue; */
}
.user-photo {
	display: flex;
	flex-direction: row;
	justify-content: center;
}
.user-info image {
	width: 70rpx;
	border-radius: 50%;
}
.user-detail {
	height: 80%;
	display: flex;
	flex-direction: column;
	flex-grow: 2;
	margin-left: 10rpx;
	/* background-color: burlywood; */
}
.user-fire {
	height: 50rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	/* background-color: aquamarine; */
}
.user-name {
	font-size: 25rpx;
	font-weight: 500;
	letter-spacing: 3rpx;
	/* background-color: aqua; */
}
.text-name {
	margin-left: 10rpx;
}
.user-flag {
	display: flex;
	flex-direction: row;
	/* background-color: brown; */
}
.user-flag view {
	font-weight: 100;
	color: white;
	font-size: 20rpx;
	margin-right: 10rpx;
	padding: 5rpx;
	border-radius: 4rpx;
}
.article-sort {
	background-color: burlywood;
}
.user-sex {
	background-color: chocolate;
}
.user-level {
	background-color: cornflowerblue;
}
.sort-content-middle {
	width: 90%;
	margin-left: auto;
	text-align: center;
	/* background-color: cornsilk; */
}
.acticle-text {
	word-wrap: break-word;
	font-size: 30rpx;
	display: -webkit-box;
	text-align: left;
	padding: 0 20rpx 0 0;
	overflow: hidden;
	margin-left: 7rpx;
	-webkit-line-clamp: 6;
	-webkit-box-orient: vertical;
	letter-spacing: 3rpx;
}
.acticle-image {
	display: flex;
	height: auto;
	flex-wrap: wrap;
}
.show {
	width: 100%;
	height: 150rpx;
	display: flex;
	text-align: start;
	white-space: nowrap;
	/* background-color: rgb(33, 122, 122); */
}
.show-image image {
	display: inline-block;
	width: 100%;
	height: 100%;
	margin: 5rpx;
	border-radius: 10rpx;
}
/* 更多 */
.post-detail {
	display: block;
	height: 80%;
	width: 200rpx;
	/* background-color: chartreuse; */
}
.handle {
	padding-left: 170rpx;
}
.handle image {
	width: 35rpx;
	height: 35rpx;
	text-align: right;
}
.post-time {
	margin-top: -20rpx;
	/* background-color: cornflowerblue; */
	display: block;
	float: right;
}
.post-time text {
	font-size: 22rpx;
	color: #a09c9c;
}
/* 底部评论等 */
.bottom-img {
	width: 35rpx;
	height: 35rpx;
	vertical-align: middle;
}
.sort-content-bottom {
	width: 90%;
	height: 52rpx;
	margin-top: 20rpx;
	margin-left: auto;
	display: flex;
	align-content: center;
	align-items: center;
}
.sort-content-btn-box {
	margin-top: 20rpx;

	display: flex;
	justify-content: space-between;
}
.content-text-ps {
	font-size: 24rpx;
}
</style>
